package com.itheima.day06.demo2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Demo2 {
    //新牌
    private static List<Card> cards = new ArrayList<>();

    static {
        String[] sizes = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        String[] colors = {"♥", "♠", "♦", "♣"};

        int index = 0;
        for (String size : sizes) {
            index++;
            for (String color : colors) {
                Card card = new Card(size, color, index);
                cards.add(card);
            }
        }

        Card xiaoWang = new Card("", "小王", ++index);
        Card k = new Card("", "大王", ++index);
        Collections.addAll(cards, k, xiaoWang);

        System.out.println("新牌:" + cards);
    }


    public static void main(String[] args) {
        //洗牌
        Collections.shuffle(cards);
        System.out.println("洗牌后:" + cards);
        //发牌+底牌51+3
        List<Card> gamePlayer1 = new ArrayList<Card>();
        List<Card> gamePlayer2 = new ArrayList<Card>();
        List<Card> gamePlayer3 = new ArrayList<Card>();
        List<Card> aHand =cards.subList(cards.size() - 3, cards.size());


        for (int i = 0; i < (Demo2.cards.size() - 3); i++) {
            Card card = Demo2.cards.get(i);
            if (i % 3 == 0) {
                gamePlayer1.add(card);
            } else if (i % 3 == 1) {
                gamePlayer2.add(card);
            }else if (i % 3 == 2) {
                gamePlayer3.add(card);
            }
        }
        //玩家手中牌排序
        sortCards(gamePlayer1);
        sortCards(gamePlayer2);
        sortCards(gamePlayer3);

        System.out.println("gamePlayer1="+gamePlayer1);
        System.out.println("gamePlayer2="+gamePlayer2);
        System.out.println("gamePlayer3="+gamePlayer3);
        System.out.println("aHand = " + aHand);


    }

    private static void sortCards(List<Card> gamePlayer) {
        Collections.sort(gamePlayer,(o1,o2)->o2.getIndex()-o1.getIndex());
    }
}
